package com.orm.base.util;

import com.orm.base.wrapper.MyLambdaQueryWrapper;
import com.orm.base.wrapper.base.WhereCondition;

import java.util.List;

public class SqlGenUtil {


    public static String genQuerySql(MyLambdaQueryWrapper<?> queryWrapper, String tableName) {
        List<WhereCondition> whereConditions = queryWrapper.getWhereConditions();
        StringBuilder querySql = new StringBuilder();
        querySql.append("SELECT ");
        querySql.append("* ");
        querySql.append("FROM ");
        querySql.append(tableName);
        querySql.append(" ");
        querySql.append("WHERE ");
        whereConditions.forEach(condition -> {

            querySql.append(condition.getDbFiledName());
            querySql.append(" ");
            querySql.append(condition.getOpString());
            querySql.append(" ");
            querySql.append(condition.getValue());
            querySql.append(" ");

        });
        querySql.append(";");

        return querySql.toString();
    }


}
